package com.cloud.logger.zchain.zchainserver.controller;

import com.cloud.logger.zchain.core.common.base.ResultMessage;
import com.cloud.logger.zchain.core.common.constant.ResultCodeConstant;
import com.cloud.logger.zchain.zchainserver.base.PagePo;
import com.cloud.logger.zchain.zchainserver.entity.AngelaLogger;
import com.cloud.logger.zchain.zchainserver.entity.vo.AngelaLoggerVo;
import com.cloud.logger.zchain.zchainserver.mongo.AngelaEntityRepository;
import com.cloud.logger.zchain.zchainserver.entity.po.AngelaLoggerPo;
import com.cloud.logger.zchain.zchainserver.service.AngelaEntityService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

/**
 * User: wcy
 * Date: 2017/11/7
 * Time: 13:31
 */
@RestController
@RequestMapping(value = "angelaLogger")
@Api(value = "/日志查询模块", description = "日志查询模块")
public class AngelaLoggerCtl {

    @Resource
    private AngelaEntityService angelaEntityService;

    @Resource
    private AngelaEntityRepository angelaEntityRepository;

    @PostMapping(value = "findLogger")
    @ApiOperation(value = "通过条件查询日志信息")
    public List<AngelaLoggerVo> findLogger(@RequestBody PagePo<AngelaLoggerPo> pagePo){
        return angelaEntityService.findLoggerByPage(pagePo);
    }

    @GetMapping(value = "findLogger/{uuid}")
    @ApiOperation(value = "通过uuid获取树形结构的日志信息")
    public List<AngelaLogger> findLogger(@PathVariable(value = "uuid") String uuid){
        return angelaEntityService.findLoggerByUuid(uuid);
    }

    @ResponseBody
    @GetMapping(value = "{id}")
    @ApiOperation(value = "通过id获取信息")
    public ResultMessage<AngelaLogger> getLoggerProject(@PathVariable String id){
        ResultMessage resultMessage = new ResultMessage();
        AngelaLogger resultinfo = angelaEntityRepository.findOne(id);

        if (resultinfo !=null){
            resultMessage.setCode(ResultCodeConstant.SERVICE_SUCCESS_CODE);
            resultMessage.setContent(resultinfo);
        }else{
            resultMessage.setCode(ResultCodeConstant.SERVICE_ERROR_CODE);
        }
        return resultMessage;
    }

}